package com.study.happystudy.po;

import com.study.happystudy.tool.ColorChange;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Data
public class WfsQuestion {
    @Data
    static class Options {
        private String lable;
        private String value;
        public Options(String lable, String value) {
            this.lable = lable;
            this.value = value;
        }
    }

    private String from_lib;
    private String exam_id;
    private int exam_index;
    private int exam_type;
    private String exam_title;
    private List<Options> exam_options;
    private String exam_answer;
    private String analysis;
    private String comment = "懒狗前端";

    public WfsQuestion(String from_lib, String exam_id, int exam_index, int exam_type, String exam_title, List<Options> exam_options, String exam_answer, String analysis) {
        this.from_lib = from_lib;
        this.exam_id = exam_id;
        this.exam_index = exam_index;
        this.exam_type = exam_type;
        this.exam_title = exam_title;
        this.exam_options = exam_options;
        this.exam_answer = exam_answer;
        this.analysis = analysis;
    }
    public WfsQuestion(){}

    public List<WfsQuestion> toWfs(ExamPaper examPaper){
        String lib = examPaper.getName();
        String eid = "lib_"+examPaper.getExamPaperId();

        final Map<String, Integer> sbPooh = Map.of("单选题", 0, "多选题", 1, "判断题", 2);

        List<WfsQuestion> res = new ArrayList<>();

        List<Question> questions = examPaper.getQuestions();
        for (int i = 0; i < questions.size(); i++) {
            Question question = questions.get(i);
            int exam_index = i+1;
            Integer exam_type = sbPooh.get(question.getQuestionType());
            if(exam_type == null) continue;
            String exam_title = question.getDescription();
            String exam_answer = question.getCorrectAnswer();
            String analysis = question.getAnalysis();

            List<Options> exam_options = new ArrayList<>();
            List<String> options = question.getOptions();
            for (String option : options) {
                try {
                    if(option.length() < 2){
                        continue;
                    }
//                    ColorChange.Blue(option + "\n");
                    String[] ss = option.split(":");
                    exam_options.add(new Options(ss[0], ss[1]));
                }catch (Exception e){
                    ColorChange.Red("Fuck: " + e.getMessage()+",后端嘻嘻不想筛了\n");
                }
            }

            res.add(new WfsQuestion(lib, eid, exam_index, exam_type, exam_title, exam_options, exam_answer, analysis));
        }

        return res;
    }
}
